package com.ypx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionsDemo {
    public static void main(String[] args) {

        //test0();
        test1();




    }

    private static void test0() {
        List<String> list = new ArrayList<>();//多态的写法
        Collections.addAll(list, "apple", "banana", "orange");
        list.forEach(System.out::println);

        System.out.println("------------------");
        //打乱的顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }


    public static void test1(){

        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1,2,3,4,5,6,7,8,9,10);
        //添加元素
        //排序
        Collections.sort(list);
        list.forEach(System.out::println);
//        Collections.sort(list,new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o2.compareTo(o1);
//            }
//        });
        Collections.sort(list,(o1,o2)-> {
            //安排倒序
            return o2 - o1;
        });
        System.out.println("----------");
        list.forEach(System.out::println);
        //让学生Student实现Comparable接口，这样也能给学生排序
        System.out.println("----");
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student( "赵六",22));
        list1.add(new Student( "张三",20));
        list1.add(new Student( "王五",18));
        Collections.sort(list1);//排序的功能
        list1.forEach(System.out::println);

    }


}
